class Node:
    def __init__(self,value,left=None,right=None):
        self.value = value
        self.left = left
        self.right = right


def createLink(): # 创建链表
    head = Node(0)
    p = head
    for i in range(1,11):
        p.right = Node(i) # 右连接下一个
        p.right.left = p # 左连接上一个
        p = p.right # 移动
    return head

def insertLink(x,head): # 插入x元素
    p = Node(x)
    p.right = head.right # 插入的结点建立右连接
    p.right.left = p # 再建立其左连接
    head.right = p # 头和插入结点建立右连接
    p.left = head # 再建立其左连接
    return head

def deleteLink(x,head): # 删除x元素
    p = head
    while p != None:
        if p.value == x:
            p.right.left = p.left # 建立左连接
            p.left.right = p.right # 建立右连接
        p = p.right
    return head

def showLink(head):
    p = head.right
    while p!= None:
        print(p.value,end=" ")
        p = p.right
    print("")


if __name__ == '__main__':
    head = createLink()
    n = int(input())
    for i in range(n):
        x = int(input())
        deleteLink(x,head)
        insertLink(x,head)
        showLink(head)
